/**
 * <p>Copyright: Copyright (c) 2014</p>
 * <p>Company: ---Technology Co. Ltd</p>
 * <p>2014-4-30</p>
 * @author Jan.Zhang
 */
package com.xianl.busiplat.service.impl;

import java.util.List;
import java.util.Set;
import com.google.common.collect.Sets;
import com.xianl.busiplat.dao.BaseDao;
import com.xianl.busiplat.dao.UserRoleDao;
import com.xianl.busiplat.po.RolePermission;
import com.xianl.busiplat.po.UserRole;
import com.xianl.busiplat.service.UserRoleService;


/** 
 * desc:
 * <p>author: Jan.Zhang </p>
 * date: 2014-4-30
 */
public class UserRoleServiceImpl extends BaseServiceImpl<UserRole> implements UserRoleService {

	private UserRoleDao userRoleMapper;
	
	/* 
	 * desc:
	 * @see com.umpay.sc.plat.core.service.UserRoleService#find(int)
	 */
	@Override
	public List<UserRole> find(int userId) {
		return  userRoleMapper.getPermissions(userId);
	}
	
	
	@Override
	public Set<String> findPermissions(int userId) {
		List<UserRole> list = userRoleMapper.getPermissions(userId);
		Set<String> permissionSet = Sets.newHashSet();
		for(UserRole r : list){
			for(RolePermission p : r.getPermissions()){
				permissionSet.add(p.getPermission());
			}
		}
		return permissionSet;
	}
	
	/* 
	 * desc:
	 * @see com.umpay.sc.plat.core.service.impl.BaseServiceImpl#setMapper(com.umpay.sc.plat.core.mapper.BaseMapper)
	 */
	@Override
	public void setMapper(BaseDao<UserRole> mapper) {
		super.setMapper(mapper);
		this.userRoleMapper = (UserRoleDao) mapper;
	}
}
